package com.example.serverdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.serverdemo.service.UserService;
import com.example.serverdemo.storage.entity.UserEntity;
import com.example.serverdemo.storage.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author: liyanfeng
 * @date: 2022/3/24 0:44
 * @Description:
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity>
        implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public UserEntity getUser(String username){
        UserEntity userEntity = lambdaQuery()
                .eq(UserEntity::getSUserName,username)
                .one();
        return userEntity;
    }

    @Override
    public UserEntity getUser(UserEntity userEntity) {
        UserEntity user = lambdaQuery().eq(UserEntity::getSUserName,userEntity.getSUserName()).eq(UserEntity::getSPwd,userEntity.getSPwd()).one();
        return user;
    }

    @Override
    public void update(UserEntity userEntity) {
        UpdateWrapper<UserEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("sUserName",userEntity.getSUserName()).set("sPwd",userEntity.getSPwd());
        userMapper.update(null, updateWrapper);
    }
}
